<?php
declare (strict_types = 1);

namespace app\index\controller;
use app\BaseController;
use think\facade\Request;
use think\facade\View;//单列设计模式
class Index extends BaseController
{
    public function index()
    {





        //赋值
        //1.赋值标量(字符串、整型、浮点、布尔类型、 不可再分的数据类型=>复合数据类型)到模板
//        $str='<b>zhuoxinag</b>';
//        View::assign('str',$str);
//
//        $arr1=[24,2021,1];
//        View::assign('arr1',$arr1);
//        $arr2=[
//            'name'=>'张三',
//            'age'=>'18'
//        ];
//        View::assign('person',$arr2);
//
//
//        $arr=[
//            ['id'=>1,'name'=>'张三','age'=>'18','sex'=>'男'],
//            ['id'=>2,'name'=>'李四','age'=>'28','sex'=>'女'],
//            ];
//        View::assign('persons',$arr);
//        View::assign([
//            'time'=>time(),
//            'a'=>10,
//            'b'=>10,
//            'url'=>'url'
//        ]);
//
//        $obj=new \stdClass();
//        $obj->name='zhuoxiang';
//        $obj->nickname='卓象';
//        View::assign('obj',$obj);
//        View::assign($arr2);
//
//        $num=5;
//        View::assign('num',$num);
        //渲染模板
        //模板跟控制器和方法只是一个默认的对应关系(规则)  仅仅是为了找模板方便而设定的规则而已
        //按照模板对应关系的控制器不一定存在
        //参数1:渲染模板  默认不写是该控制器的方法对应的模板
        //               模板表达式  [应用@][控制器/][方法]  从右向左一次可以省略
        //               支持相对路径找到模板
//        return View::fetch();
//        return View::fetch('index@index/index');

//默认值: 当无法接到参数是或者没有传参时(接到的参数值为NULL时),会自动使用默认值来当做参数的值;






        return View::fetch();
    }
    public function test()
    {

        echo "<pre>";
        print_r(Request::only(['hobby'],'post'));
        echo "</pre>";

        echo "<pre>";
        print_r(Request::except(['hobby'],'post'));
        echo "</pre>";
        echo "<hr>";
        var_dump(Request::has('username','post')); echo "<br>";
        var_dump(Request::has('username','get'));
        echo "<hr>";

        echo "<pre>";
        print_r(input('post.hobby'));
        echo "</pre>";

        echo "<pre>";
        print_r(input('post.'));
        echo "</pre>";


        echo "<hr>";
        echo Request::url();
        echo "<br>";
        echo Request::contentType();
        echo "<br>";
        echo Request::pathinfo();
        echo "<br>";
        echo Request::controller();
        echo "<br>";
        echo Request::action();
        echo "<br>";

        echo Request::param('name');
        echo Request::param('age');



        $name=Request::param('username/d');
        var_dump($name);
        $hobby=Request::post('hobby/a');
        echo "<pre>";
        print_r($hobby);
        echo "</pre>";

        $sex=Request::param('sex/b');
        var_dump($sex);


        echo "<hr>";
        var_dump(Request::param('naem','123'));
        echo "<hr>";
        var_dump(Request::get('name','123'));
        echo "<hr>";
        var_dump(Request::post('username','123'));
        echo "<hr>";




        echo "<pre>";
        print_r(Request::param());
        echo "</pre>";

        echo "<pre>";
        print_r(Request::post());
        echo "</pre>";

        echo "<hr>";
        var_dump(Request::post('username','123'));
        echo "<hr>";
        var_dump(Request::post('username','123','trim,htmlspecialchars'));
        echo "<hr>";
        var_dump(Request::post('username','123','trim,strip_tags'));
        echo "<hr>";
        var_dump(Request::post('username','123','trim,htmlspecialchars,strip_tags'));
        echo "<hr>";
        var_dump(Request::post('username','123','md5,strtoupper'));

        return View::fetch();
    }
    public function form()
    {
        return View::fetch();
    }
}
